function getStyle (dom, propName) {
    if (getComputedStyle) {
        return getComputedStyle(dom)[propName];
    } else {
        return dom.currentStyle()[propName];
    }
}
function style (dom, cssJson) {
    dom.style.cssText = Object.keys(cssJson).reduce(function (previousValue, currentValue) {
        return previousValue + currentValue + ':' + cssJson[currentValue] + ';';
    }, '');
}
/*
 * @param dom :节点
 * @param attrName :属性名
 * @param attrValue :属性值
 * @return {string}
 */
function attr (dom, attrName, attrValue) {
    if (!attrValue) {
        return dom.getAttribute(attrName);
    } else {
        dom.setAttribute(attrName, attrValue);
    }
}
/**
 * 事件绑定兼容方法
 * @param obj ： 节点
 * @param type ： 事件
 * @param handle ： 函数
 * @param boolean ： 不传默认冒泡，传true阻止冒泡
 */
function addEvent (obj, type, handle, boolean) {
    if (obj.addEventListener) {
        boolean ? obj.addEventListener(type, function (e) {
            handle();
            e.stopPropagation();
        }) : obj.addEventListener(type, handle);
    } else {
        boolean ? obj.attachEvent('on' + type, function (e) {
            handle();
            e.cancelBubble = true;
        }) : obj.attachEvent('on' + type, handle);
    }
}
window.onload = function () {
    /* 导航栏部分 */
    topNav();
    function topNav () {
        var con = document.getElementById('topNav');// 获取到导航栏来改变背景颜色
        var img = document._getElementByClassName('topNav_top-logo-bg')[0];// 获取到img来改变LOGO图片
        var toTop = document.getElementsByClassName('toTop')[0];
        addEvent(window, 'scroll', function () {
            var t = document.documentElement.scrollTop || document.body.scrollTop;
            if (t <= 0) { //  判断当前的鼠标距离  和  窗口距离是否一样
                // 如果是一样就代表已经到了顶部 改变背景颜色为透明  和字体颜色以logo图片
                style(con, { 'color': '#fff', 'background': 'transparent' });
                attr(img, 'src', './image/logo-new.png');
                toTop.style.opacity = '0';
            } else {
                // 如果不是一样就代表没到顶部 改变背景颜色为白色  和字体颜色以logo图片
                style(con, { 'color': '#000', 'background': '#fff' });
                con.style.boxShadow = '#929292 1px 1px 1px ';
                attr(img, 'src', './image/logo.png');
                toTop.style.opacity = '1';
            }
        });
    }
    // 轮播
    moveGo();
    function moveGo () {
        var _dom = document._getElementByClassName('Carousel')[0];
        var _prev = document._getElementByClassName('Carousel_prev')[0];
        var _next = document._getElementByClassName('Carousel_next')[0];
        var _list = document._getElementByClassName('Carousel_list')[0];
        var _itemLen = document._getElementByClassName('Carousel_list-item').length - 1;
        var _itemRu = document._getElementByClassName('Carousel_ru');
        var _itemW = parseInt(getStyle(document._getElementByClassName('Carousel_list-item')[0], 'width'));
        var terms = null;
        var counter = 0;

        autopy();
        function autopy () {
            terms = setInterval(function () {
                next();
            }, 2000);
        }
        function next () {
            Animation(_list, -_itemW, 300, 'easeInOut', -_itemW * counter);
            iRu(counter);
            counter++;
            if (counter >= _itemLen) {
                counter = 0;
            }
        }
        function prev () {
            if (counter <= 0) {
                counter = _itemLen;
            }
            Animation(_list, _itemW, 300, 'easeInOut', -_itemW * counter);
            counter--;
        }
        addEvent(_prev, 'click', function () {
            iRu(counter);
            clearInterval(terms);
            prev();
        });
        addEvent(_next, 'click', function () {
            clearInterval(terms);
            next();
        });
        addEvent(_dom, 'mousemove', function () {
            clearInterval(terms);
        });
        addEvent(_dom, 'mouseout', function () {
            autopy();
        });

        function iRu (index) {
            _itemRu.forEach(function (value) {
                value.style.background = '#fff';
            });
            _itemRu.forEach(function (value, index, array) {
                addEvent(value, 'click', function () {
                    _itemRu.forEach(function (value) {
                        value.style.background = '#fff';
                    });
                    array[index % _itemLen].style.background = '#dd4d48';
                    if (index > counter) {
                        counter = index;
                        if (counter <= 0) {
                            counter = 3;
                        }
                        Animation(_list, _itemW, 300, 'easeInOut', -_itemW * counter);
                    } else {
                        counter = index;
                        Animation(_list, -_itemW, 300, 'easeInOut', -_itemW * counter);
                    }
                });
            });
            _itemRu[index % _itemLen].style.background = '#dd4d48';
        }
    }
    // 公告
    notice();
    function notice () {
        var _list = document._getElementByClassName('notice_list')[0];
        var _itemLen = document._getElementByClassName('notice_list-item').length / 2;
        var listW = parseInt(getStyle(document._getElementByClassName('notice_list-item')[0], 'height'));
        var index = 0;
        var terms = null;
        function f () {
            terms = setInterval(function () {
                if (index === _itemLen) {
                    index = 0;
                }
                _list.style.top = -listW * index + 'px';
                index++;
            }, 2000);
        }

        addEvent(_list, 'mousemove', function () {
            clearInterval(terms);
        });
        addEvent(_list, 'mouseout', function () {
            f();
        });
        f();
    }
    // 中间
    content();
    function content () {
        var _contentLink = document._getElementByClassName('content_title-link');
        var contentTail = document._getElementByClassName('content_con_detail');
        var _contentImg = document._getElementByClassName('content_title-link-bg');
        var _contentAll = document._getElementByClassName('content')[0];
        _contentLink[0].style.color = '#61a0cc';
        attr(_contentImg[0], 'src', './image/index_icon1.png');
        contentTail[0].style.opacity = 1;
        var index = 0;
        var terms = null;
        var src = ['./image/index_icon1-1.png', './image/index_icon2-2.png', './image/index_icon3-3.png', './image/index_icon4-4.png', './image/index_icon5-5.png'];
        move();
        function move () {
            terms = setInterval(function () {
                _contentImg.forEach(function (value, index) {
                    attr(value, 'src', src[index]);
                });
                contentTail.forEach(function (value) {
                    value.style.opacity = 0;
                });
                _contentLink.forEach(function (value) {
                    value.style.color = '#707070';
                });
                attr(_contentImg[index], 'src', './image/index_icon' + (index + 1) + '.png');
                contentTail[index].style.opacity = 1;
                _contentLink[index].style.color = '#61a0cc';
                index++;
                index = index >= _contentImg.length ? 0 : index;
            }, 2200);
        }
        addEvent(_contentAll, 'mousemove', function () {
            clearInterval(terms);
        });
        addEvent(_contentAll, 'mouseout', function () {
            move();
        });
        _contentLink.forEach(function (value, key, array) {
            addEvent(value, 'mousemove', function () {
                index = key;
                contentTail.forEach(function (value) {
                    value.style.opacity = 0;
                });
                _contentImg.forEach(function (value, index) {
                    attr(value, 'src', src[index]);
                });
                _contentLink.forEach(function (value) {
                    value.style.color = '#707070';
                });
                value.style.color = '#61a0cc';
                contentTail[key].style.opacity = 1;
                attr(_contentImg[key], 'src', './image/index_icon' + (key + 1) + '.png');
            });
        });
    }
    // caseCar
    caseCar();
    function caseCar () {
        var _dom = document._getElementByClassName('caseCar_all')[0];
        var _prev = document._getElementByClassName('caseCar_all-prev')[0];
        var _next = document._getElementByClassName('caseCar_all-next')[0];
        var _list = document._getElementByClassName('caseCar_all-list')[0];
        var _itemLen = document._getElementByClassName('caseCar_all-list-item').length - 1;
        var _itemRu = document._getElementByClassName('caseCar_all-ru-item');
        _itemRu[0].style.background = '#dd6c5a';
        var _itemW = parseInt(getStyle(document._getElementByClassName('caseCar_all-list-item')[0], 'width'));
        var terms = null;
        var counter = 0;
        attr(_itemRu[1], 'index', '0');
        attr(_itemRu[2], 'index', 1);
        attr(_itemRu[0], 'index', 2);
        autopy();
        function autopy () {
            terms = setInterval(function () {
                next();
            }, 2000);
        }
        function next () {
            Animation(_list, -_itemW, 300, 'easeInOut', -_itemW * counter);
            itRu(counter);
            counter++;
            if (counter >= _itemLen) {
                counter = 0;
            }
        }
        function prev () {
            if (counter <= 0) {
                counter = _itemLen;
            }
            Animation(_list, _itemW, 300, 'easeInOut', -_itemW * counter);
            counter--;
        }
        addEvent(_prev, 'click', function () {
            itRu(counter);
            clearInterval(terms);
            prev();
        });
        addEvent(_next, 'click', function () {
            clearInterval(terms);
            next();
        });
        addEvent(_dom, 'mousemove', function () {
            clearInterval(terms);
        });
        addEvent(_dom, 'mouseout', function () {
            autopy();
        });
        function itRu (index) {
            _itemRu.forEach(function (value) {
                value.style.background = '#fff';
            });
            switch (index) {
                case index = 0:
                    _itemRu[1].style.background = '#dd6c5a';
                    break;
                case index = 1:
                    _itemRu[2].style.background = '#dd6c5a';
                    break;
                case index = 2:
                    _itemRu[0].style.background = '#dd6c5a';
            }
            _itemRu.forEach(function (value, index, array) {
                addEvent(value, 'click', function () {
                    _itemRu.forEach(function (value) {
                        value.style.background = '#fff';
                    });
                    array[index % _itemLen].style.background = '#dd4d48';
                    if (index > counter) {
                        counter = index;
                        if (counter <= 0) {
                            counter = 3;
                        }
                        Animation(_list, _itemW, 300, 'easeInOut', -_itemW * counter);
                    } else {
                        counter = index;
                        Animation(_list, -_itemW, 300, 'easeInOut', -_itemW * counter);
                    }
                });
            });
        }
    }
    // personnel
    personnel();
    function personnel () {
        var dom = document._getElementByClassName('personnel')[0];
        var _item = document._getElementByClassName('personnel_all-ist-item');
        var _itemBg = document._getElementByClassName('personnel_all-ist-item_bg');
        var _text = document._getElementByClassName('personnel_all-text');
        var trems = null;
        var index = 0;
        move();
        function move () {
            trems = setInterval(function () {
                index++;
                index = index >= 5 ? 0 : index;
                _item.forEach(function (value) {
                    value.style.color = '#fff';
                });
                _itemBg.forEach(function (value) {
                    value.style.border = 'none';
                });
                _itemBg[index].style.borderColor = '#EDAB00';
                _itemBg[index].style.borderWidth = '2px';
                _itemBg[index].style.borderStyle = 'solid';
                _text.forEach(function (value) {
                    value.style.display = 'none';
                });
                _item[index].style.color = '#EDAB00';
                _text[index].style.display = 'block';
            }, 3000);
        }
        addEvent(dom, 'mousemove', function () {
            clearInterval(trems);
        });
        addEvent(dom, 'mouseout', function () {
            move();
        });
        _item.forEach(function (value, key) {
            addEvent(value, 'mousemove', function () {
                index = key;
                _text.forEach(function (value) {
                    value.style.display = 'none';
                });
                _itemBg.forEach(function (value) {
                    value.style.border = 'none';
                });
                _item.forEach(function (value) {
                    value.style.color = '#fff';
                });
                _itemBg[key].style.borderColor = '#EDAB00';
                _itemBg[key].style.borderWidth = '2px';
                _itemBg[key].style.borderStyle = 'solid';
                _item[key].style.color = '#EDAB00';
                _text[key].style.display = 'block';
            });
        });
        var apply = document._getElementByClassName('apply')[0];
        addEvent(window, 'scroll', function () {
            var t = document.documentElement.scrollTop || document.body.scrollTop;
            if (t <= 1600) {
                dom.style.backgroundPositionY = '-5px';
            }
            if (t >= 2300) {
                dom.style.backgroundPositionY = '5px';
            }
            if (t <= 2700) {
                apply.style.backgroundPositionY = '-5px';
            }
            if (t >= 3440) {
                apply.style.backgroundPositionY = '5px';
            }
        });
    }
    // dynamic
    dynamic();
    function dynamic () {
        var list = document._getElementByClassName('dynamic_list-left_list-item');
        var item = document._getElementByClassName('dynamic_list-left_list-item_list');
        list[0].style.color = '#2597b';
        list.forEach(function (value, index) {
            addEvent(value, 'mousemove', function () {
                list.forEach(function (value) {
                    value.style.color = '#000';
                });
                item.forEach(function (value) {
                    value.style.display = 'none';
                });
                item[index].style.display = 'block';
                value.style.color = '#2597bb';
            });
        });
    }
};
